import 'dart:math';

import 'package:flame/game.dart';
import 'package:flutter/material.dart';

class Bullet extends FlameGame {
  Bullet(
      {required this.position,
      this.speed = 5,
      this.angle = 0,
      this.radius = 10});

  final Vector2 position;
  final double speed;
  final double angle;
  final double radius;
  final Paint paint = Paint()..color = Colors.green;
  final Path path = Path();
  bool isMove = true;

  @override
  Future<void> onLoad() async {
    path.addOval(Rect.fromLTWH(
        position.x - radius, position.y - radius, radius * 2, radius * 2));
  }

  @override
  void render(Canvas canvas) {
    canvas.drawCircle(position.toOffset(), radius, paint);
  }

  void update(double dt) {
    if (isMove) {
      position.setValues(
          position.x - cos(angle) * speed, position.y - sin(angle) * speed);
      path.reset();
      path.addOval(Rect.fromLTWH(
          position.x - radius, position.y - radius, radius * 2, radius * 2));
    }else{
    }
    var eventPosition = position;
    
    // if (eventPosition.x < radius) {
    //   removeFromParent();
    //   // return;
    // }
    // if (eventPosition.x > canvasSize.x - radius) {
    //   removeFromParent();
    //   return;
    // }
    // if (eventPosition.y < radius) {
    //   removeFromParent();
    //   return;
    // }
    // if (eventPosition.y > canvasSize.y - radius) {
    //   removeFromParent();
    //   return;
    // }
  }

  void isStopMove(bool isStop) {
    // print('设置为');
    // print(isStop);
    isMove = isStop;
  }
}
